home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7246 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.2 KB

  1. Path: server-b.cs.interbusiness.it!usenet
  2. From: albe@pinerolo.gvo.it (Alberto Velo)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Watcom: pad a string ?
  5. Date: Tue, 13 Feb 1996 19:35:44 -0100
  6. Organization: Centro Servizi Interbusiness
  7. Distribution: world
  8. Message-ID: <gYPIxQTC3YkO089yn@pinerolo.gvo.it>
  9. References: <ZCOExQTC3kJT089yn@pinerolo.gvo.it>
  10.  <4f2ftf$rjb@sparcserver.lrz-muenchen.de>
  11. Reply-To: albe@pinerolo.gvo.it
  12. NNTP-Posting-Host: pittys17.gvo.it
  13.  
  14. In article <4f2ftf$rjb@sparcserver.lrz-muenchen.de>,
  15. ua302aa@sun2.lrz-muenchen.de (Kurt Watzka) wrote: 
  16.  
  17. >>I have an array, part of a structure (i.e. msg.from="Myname"); since array is 
  18. >>of defined length in the structure ( char from[36] ), I'd need to let msg.from 
  19. >>36 chars length, padding it with spaces.
  20. >Why do you think so? As long as "msg.from" indeed _is_ a string, i.e. if
  21. >it is '\0'-terminated, there is no need to pad it with spaces. If you 
  22.  
  23. I don't need actually: the problem was that the array was part of a structure, 
  24. and I wrote the entire structure binarily onto a file. As long as I was told 
  25. the right way to do that is NOT to write the entire structure in one, but the 
  26. different members one by one, my problem was solved.
  27. The structure, for instance, is a Fidonet packet.
  28.  
  29. >>sizeof(structname), while char arrays are shorter than the ones defined in 
  30. >>struct, I find additional garbage chars in the file, who fill the array 
  31. >sizes.
  32. >So what? You want to write the whole structure, you write it. Those
  33. >"additional garbare chars" are in the struct, and they appear in the
  34. >file. If you want to avoid storing "garbage" chars, you cannot use
  35. >arrays of characters with a fixed size.
  36.  
  37. That's the problem: avoid garbages and do use fixed-length arrays. The solution
  38. is to write each member one by one, or pad the string.. but the former method 
  39. is used in a couple of sources I saw, so I use it myself ;).
  40.  
  41. -- 
  42. Bye,   AL!
  43.         
  44.                      E-mail : albe@pinerolo.gvo.it
  45.    Team OS/2 ITA     Fidonet: 2:334/708 2:334/708.1
  46.                      OS2net : 81:439/63 81:439/63.1
  47.  
  48.             ***********************************************
  49.               Pinerolo Internetworking BBS +39-121-393945
  50.                        Telnet bbs.piw.gvo.it
  51.             ***********************************************
  52.